home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-05
/
lanutsrc.zip
/
SYSTEM.C
< prev
next >
Wrap
Text File
|
1991-03-13
|
13KB
|
451 lines
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* SYSTEM.C
* *
* AUTHOR: Jon Marbry *
* *
* HISTORY: *
* 1/25/90 JEM Created *
* *
* WHAT: *
* SYSTEM allows the user's batch files to access information about the *
* computer's operating hardware and software *
* *
* INPUT: *
* *
* OUTPUT: *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <ctype.h>
#include "hardware.h"
#include "lantasti.h"
struct token_table {
char *token; /* keyword */
int type; /* keyword classifier */
int (*vfn)(); /* function to evaluate for value substitution */
int value; /* integer value to return if CONST and no fn. given */
};
enum token_class {CPU,FPU,VIDEO,MEM,DISK,EXT,EXP,MOUSE,DOSVER,LANVER,CONST,
EQ,NE,LT,GT,LE,GE,AND,OR,RPAR,LPAR,USER,RESULT};
char *class_names[] = {"CPU","FPU","VIDEO","MEM","DISK","EXT","EXP","MOUSE",
"DOSVER","LANVER","CONST","EQ","NE","LT","GT","LE",
"GE","AND","OR","RPAR","LPAR","USER","RESULT"};
struct token_table keywords[] = {
{"CPU",CPU,cpu_type,0},
{"FPU",FPU,fpu_present,0},
{"VIDEO",VIDEO,video_type,0},
{"MEMORY",MEM,ram_free,0},
{"MEM",MEM,ram_free,0},
{"DISK",DISK,disk_space,0},
{"EXPANDED",EXP,ems_avail,0},
{"EXP",EXP,ems_avail,0},
{"EXTENDED",EXT,ext_avail,0},
{"EXT",EXT,ext_avail,0},
{"MOUSE",MOUSE,mouse_present,0},
{"DOSVER",DOSVER,get_dos_version,0},
{"DOS",DOSVER,get_dos_version,0},
{"LANVER",LANVER,get_lan_version,0},
{"LAN",LANVER,get_lan_version,0},
{"=",EQ,NULL,0},
{"EQ",EQ,NULL,0},
{"==",EQ,NULL,0},
{"NE",NE,NULL,0},
{"!=",NE,NULL,0},
{"LT",LT,NULL,0},
{"GT",GT,NULL,0},
{"LE",LE,NULL,0},
{"GE",GE,NULL,0},
{"AND",AND,NULL,0},
{"&",AND,NULL,0},
{"&&",AND,NULL,0},
{",",AND,NULL,0},
{"OR",OR,NULL,0},
{"|",OR,NULL,0},
{"||",OR,NULL,0},
{")",RPAR,NULL,0},
{"(",LPAR,NULL,0},
/* general purpose constants */
{"YES",CONST,NULL,TRUE},
{"NO",CONST,NULL,FALSE},
/* processor types */
{"8088",CONST,NULL,88},
{"8086",CONST,NULL,88},
{"80286",CONST,NULL,286},
{"80386",CONST,NULL,386},
{"80486",CONST,NULL,486},
/* video board types */
{"VGA",CONST,NULL,4},
{"MCGA",CONST,NULL,4},
{"EGA",CONST,NULL,3},
{"CGA",CONST,NULL,2},
{"HERC",CONST,NULL,1},
{"HERCULES",CONST,NULL,1},
{"MONO",CONST,NULL,0},
{"MDA",CONST,NULL,0}
};
#define NUM_KEYWORDS sizeof(keywords) / sizeof(struct token_table)
/* global token stack info */
#define STACKSIZE 60
int stack[STACKSIZE];
int stack_ptr = STACKSIZE;
/* global command line and current token */
#define CMD_LINE_LENGTH 1024
char gl_line[CMD_LINE_LENGTH],gl_token[80];
char *cmdline = gl_line;
/* stack_items ********************************************************************
Report the number of items on the stack
*****************************************************************************/
int stack_items() {
return(STACKSIZE - stack_ptr);
}
/* ncompare ********************************************************************
*****************************************************************************/
ncompare(loperand,operator,roperand)
int loperand,operator,roperand;
{
switch (operator) {
case EQ:
return(loperand == roperand);
case NE:
return(loperand != roperand);
case LT:
return(loperand < roperand);
case GT:
return(loperand > roperand);
case LE:
return(loperand <= roperand);
case GE:
return(loperand >= roperand);
case AND:
return(loperand && roperand);
case OR:
return(loperand || roperand);
default:
puts("Error: Invalid relational operator encountered");
exit(-1);
break;
}
}
/* push ********************************************************************
*****************************************************************************/
push(item)
int item;
{
if (stack_ptr)
stack[--stack_ptr] = item;
else {
puts("Parser error (stack overflow)");
exit(-1);
}
}
/* pop ********************************************************************
*****************************************************************************/
int pop(item)
int item;
{
if (stack_ptr < STACKSIZE)
return(stack[stack_ptr++]);
else {
puts("Syntax error: Invalid expression");
exit(-1);
}
}
/* find ********************************************************************
Returns index of a token in the keyword table table or -1
if the token is not in the table
*****************************************************************************/
find(token)
char *token;
{
int i;
for (i = 0; i < NUM_KEYWORDS; i++) {
if (strcmp(keywords[i].token,token) == 0) break;
}
return((i < NUM_KEYWORDS) ? i : -1);
}
/* get_token ********************************************************************
Gets the next token from a text string. If successful, returns a pointer to
the current position in <string>, NULL otherwise.
*****************************************************************************/
int get_token()
{
int done,found;
struct token_table out_token;
char *token;
done = found = FALSE;
token = gl_token;
*token = 0;
while (!done) {
switch (*cmdline) {
case '\n':
case ' ': /* check for junk characters */
if (found) done = TRUE;
break;
case '=': /* check for relational operators */
case '!':
case '<':
case '>':
case '&':
case '|':
if (found) { /* if we've got a token, a rel op ends it */
done = TRUE;
cmdline--;
break;
}
else {
*token++ = *cmdline; /* otherwise, see if it's a two char rel op */
if ('=' == *(cmdline + 1)) {
cmdline++; /* copy the second character */
*token++ = *cmdline;
}
done = found = TRUE;
break;
}
case '(': /* parentheses are complete tokens, thank you */
case ')':
if (found) { /* if we've got a token, a paren ends it */
done = TRUE;
cmdline--;
break;
}
else { /* otherwise, just copy the token */
*token++ = *cmdline;
done = found = TRUE;
break;
}
case 0: /* we've come to the end of the string */
done = TRUE; found = FALSE;
break;
case '.':
break;
default:
found = TRUE;
*token++ = *cmdline;
break;
}
if (*cmdline != 0) cmdline++;
}
*token = 0; /* null terminate the token */
}
/* is_relop ********************************************************************
*****************************************************************************/
is_relop(n)
int n;
{
return((n >= EQ) && (n <= OR));
}
/* substitute ********************************************************************
*****************************************************************************/
int substitute(token,class)
char *token;
int class;
{
if (class < 0) return(atoi(token));
if (is_relop(keywords[class].type)) return(keywords[class].type);
if (keywords[class].vfn != NULL) return((*keywords[class].vfn)());
return(keywords[class].value);
}
/* evaluate ********************************************************************
*****************************************************************************/
evaluate() {
int operator,left,right,result;
while (TRUE) {
if (stack_items() < 3) break;
right = pop();
operator = pop();
left = pop();
result = ncompare(left,operator,right);
push(result);
}
}
/* report ********************************************************************
Display current system hardware and software configuration.
*****************************************************************************/
report() {
puts("SYSTEM utility for LANtastic -- Copyright 1990 by SoftMagic, Inc.");
puts("All rights reserved. LANtastic is a trademark of Artisoft, Inc.\n");
puts("Current system configuration:");
puts("───────────────────────────────────");
puts("Hardware");
printf( " CPU: 80%d\n",cpu_type());
if (fpu_present()) puts(" FPU: INSTALLED");
else puts(" FPU: NOT INSTALLED");
printf( " Video: ");
switch (video_type()) {
case 0: /* mono */
printf("Monochrome\n");
break;
case 1: /* herc */
printf("Hercules\n");
break;
case 2:
printf("CGA\n");
break;
case 3:
printf("EGA\n");
break;
case 4:
printf("MCGA/VGA\n");
break;
}
if (mouse_present()) puts(" Mouse: INSTALLED");
else puts(" Mouse: NOT INSTALLED");
puts("───────────────────────────────────");
puts("Available Memory");
printf(" Conventional: %dK\n",ram_free());
printf(" Expanded: %dK\n",ems_avail());
printf(" Extended: %dK\n",ext_avail());
puts("───────────────────────────────────");
printf("Disk space available: %dK\n",disk_space());
puts("───────────────────────────────────");
puts("Software");
printf(" DOS Version: %.2f\n", (float) get_dos_version() / 100.0);
printf(" LANtastic Version: %.2f\n",(float) get_lan_version() / 100.0);
puts("───────────────────────────────────");
}
/* process_options ********************************************************************
*****************************************************************************/
int process_options(string)
char *string;
{
if (!strcmpi(string,"HELP")) {
puts("SYSTEM utility for LANtastic -- Copyright 1990 by SoftMagic, Inc.");
puts("All rights reserved. LANtastic is a trademark of Artisoft, Inc.\n");
puts("Usage: SYSTEM <expression> [/OPTIONS]");
puts("Available options are:");
puts("/REPORT - display the computer's hardware and software configuration");
puts("/HELP - display this documentation");
exit(0);
}
else if (!strcmpi(string,"REPORT")) {
report();
exit(0);
}
else {
printf("<%s> isn't a valid command line option.\n",string);
puts("Type SYSTEM /HELP for a summary of instructions.");
}
}
/* process_file ********************************************************************
*****************************************************************************/
process_file(fname,string)
char *fname,*string;
{
FILE *file;
int length;
file = fopen(fname,"rt");
if (file == NULL) {
printf("Error: Unable to open input file %s\n",fname);
exit(-1);
}
length = fread(string,1,CMD_LINE_LENGTH,file);
string[length] = 0;
strupr(string);
puts(string);
fclose(file);
}
/* main ********************************************************************
*****************************************************************************/
int main(argc,argv)
int argc;
char *argv[];
{
int i,result,curr_item;
/* combine command line into a single string */
cmdline[0] = 0;
if (argc >= 2) {
for (i = 1;i < argc;i++) {
if (argv[i][0] == '/') { /* handle options */
process_options(&argv[i][1]);
continue;
}
else if (argv[i][0] == '@') { /* command file */
process_file(&argv[i][1],cmdline);
continue;
}
else {
strupr(argv[i]);
strcat(cmdline," ");
strcat(cmdline,argv[i]);
}
}
}
else {
process_options("HELP");
}
/* parse command line using the ol' APL scanning technique --
scan from right to left, using no precedence and ignoring parenthesis */
get_token();
while (strlen(gl_token)) {
result = find(gl_token);
if (keywords[result].type == RPAR) evaluate();
else if (keywords[result].type != LPAR) {
curr_item = substitute(gl_token,result);
push(curr_item);
}
get_token();
}
if (stack_items() >= 3) evaluate();
/* retrieve final result */
curr_item = pop();
return(!curr_item);
}